package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.WoDeShouRuBean;
import com.lwj.liwanjia.bean.WorkBean06;
import com.lwj.liwanjia.utils.BaseUtils;
import com.lwj.liwanjia.utils.GlideImageLoader;
import com.lwj.liwanjia.view.activity.work.shang_jia.ShouRuXiangQingActivity;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by 001 on 2017/9/15.
 */

public class WoDeShouRuAdapter extends RecyclerView.Adapter<WoDeShouRuAdapter.ViewHolder> {

    private Context mContext;
    private List<WorkBean06.DataBean.ItemBean> mList;

    public WoDeShouRuAdapter(Context mContext,List<WorkBean06.DataBean.ItemBean> mList) {
        this.mContext = mContext;
        this.mList = mList;

    }

    @Override
    public WoDeShouRuAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_wo_de_shou_ru, parent, false);

        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(WoDeShouRuAdapter.ViewHolder holder, int position) {

        final WorkBean06.DataBean.ItemBean itemBean = mList.get(position);

        holder.tv_money.setText(itemBean.getOneCardItemNum()+" 元");
        holder.tv_name.setText(itemBean.getPartyUserNick());
        Glide.with(mContext).load(itemBean.getPartyUserHeadImage()).into(holder.circle_photo);

        long time = itemBean.getOneCardItemTime();
        String timeResult = BaseUtils.getString(String.valueOf(time / 1000));
        holder.tv_time.setText(timeResult);

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //跳转到收入详情界面
                Intent intent = new Intent(mContext, ShouRuXiangQingActivity.class);
                intent.putExtra("id", itemBean.getOneCardItemId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        View view;
        CircleImageView circle_photo;
        TextView tv_name;
        TextView tv_money;
        TextView tv_time;

        public ViewHolder(View itemView) {
            super(itemView);

            circle_photo = (CircleImageView) itemView.findViewById(R.id.circle_photo);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
            view = itemView;
        }
    }
}
